package cn.bone.admin.base.configuration;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * Created by Administrator on 2017/9/20.
 */
public class JedisPoolFactory {

    public static volatile JedisPool pool = null;

    private JedisPoolFactory(){}

    public JedisPool getPool(){
        if(null==pool){
            synchronized (pool){
                if(null==pool){
                    String host = "127.0.0.1";
                    int port = 6379;
                    int timeout = 5000;
                    String password = "mindainfo";
                    JedisPoolConfig config = new JedisPoolConfig();
                    config.setMinIdle(5);
                    config.setMaxTotal(10);
                    config.setMaxIdle(10);
                    config.setMaxWaitMillis(5000);
                    config.setTestOnBorrow(true);   //获得一个jedis实例时检查是否可用
                    pool = new JedisPool(config,host,port,timeout,password);
                }
            }
        }
        return pool;
    }
}
